// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import EventMng from "../../Script/EventMng";
import { GameEvent } from "../../Script/GameEvent";

const { ccclass, property } = cc._decorator;

@ccclass
export default class scrollviewTagd extends cc.Component {


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    @property(cc.Node)
    img_xia: cc.Node = null;
    @property(cc.Node)
    node_tag: cc.Node = null;

    anim:any = null;
    msgName: String = 'lian';

    onClickTag(event, msg) {
        if(this.msgName == msg) {
            return;
        }
        this.msgName = msg;
        this.onTagSize();
        switch (msg) {
            case 'lian':
                this.onTagAnim(event.target);
                EventMng.emit(GameEvent.TAG_CLICK, msg);
                break;
            case 'yanjing':
                this.onTagAnim(event.target);
                EventMng.emit(GameEvent.TAG_CLICK, msg);
                break;
            case 'zuiba':
                this.onTagAnim(event.target);
                EventMng.emit(GameEvent.TAG_CLICK, msg);
                break;
            case 'meimao':
                this.onTagAnim(event.target);
                EventMng.emit(GameEvent.TAG_CLICK, msg);
                break;
            case 'toufa':
                this.onTagAnim(event.target);
                EventMng.emit(GameEvent.TAG_CLICK, msg);
                break;
            case 'erduo':
                this.onTagAnim(event.target);
                EventMng.emit(GameEvent.TAG_CLICK, msg);
                break;
            default:
                break;
        }
    }

    onTagSize() {
        for(let a = 0; a < this.node_tag.children.length - 1; a++) {
            this.node_tag.children[a].children[0].getComponent(cc.Label).fontSize = 25;
        }
    }

    onTagAnim(target: cc.Node) {
        target.children[0].getComponent(cc.Label).fontSize = 30;
        if(this.anim) {
            this.anim.stopAllByTag();
            this.anim = null;
        }
        this.anim = cc.tween(this.img_xia)
            .to(0.2,{position: cc.v3(target.x, this.img_xia.y, 0)})
            .call(() => {
                this.anim = null;
            })
            .start()
    }

    start() {

    }


}
